package com.shujia.sql

import org.apache.spark.sql.expressions.Window
import org.apache.spark.sql.{DataFrame, SparkSession}


object Test1 {
  def main(args: Array[String]): Unit = {
    val ss: SparkSession = SparkSession.builder()
      .master("local")
      .appName("spark sql练习1")
      .config("spark.sql.shuffle.partitions", "1")
      .getOrCreate()

    import ss.implicits._
    import org.apache.spark.sql.functions._

    val df1: DataFrame = ss.read
      .format("csv")
      .option("sep", ",")
      .schema("id STRING,day_time DATE,sell INT")
      .load("spark/data/t1.txt")

    df1.withColumn("next_sell", lead($"sell",1,0) over Window.orderBy($"day_time"))
      .show()

  }
}
